import request from '@/utils/request'

interface LoginParams {
  phone: string
  password: string
  userType: number
}

interface RegisterParams {
  userName: string,
  phone: string,
  password: string,
  userType: number,
  captcha: string
}

interface UserInfo {
  id: number;
  userName: string;
  email?: string;
  phone?: string;
  password?: string;
  sex?: number;
  avatar: string;
  status?: number;
  introduce?: string;
  userType?: number;
  createdBy?: string;
  createdTime?: string;
  updateBy?: string;
  updateTime?: string;
  isDeleted?: number;
}

// 登录接口
export const login = (data: {
  username: string
  password: string
}) => {
  return request({
    url: '/user/tourist/login',  // 修改为正确的游客登录接口
    method: 'post',
    data
  })
}

// 游客登录
export function touristLogin(data: LoginParams) {
  return request({
    url: '/user/tourist/login',
    method: 'post',
    data
  })
}

// 农户登录
export function farmerLogin(data: LoginParams) {
  return request({
    url: '/user/rural/login',  // 修改为正确的农户登录接口
    method: 'post',
    data
  })
}

// 游客注册
export function touristRegister(data: RegisterParams) {
  return request({
    url: '/user/tourist/register',  // 确保URL正确
    method: 'post',
    data
  })
}

// 农户注册
export function ruralRegister(data: RegisterParams) {
  return request({
    url: '/user/rural/register',
    method: 'post',
    data
  })
}

// 获取验证码
export function getVerifyCode(phone: string) {
  return request({
    url: '/user/code',
    method: 'get',
    params: { phone }
  })
}

// 获取验证码
export function getCaptcha() {
  return request({
    url: '/common/captcha',
    method: 'get'
  })
}

// 获取用户信息
export function getUserInfo() {
  return request<UserInfo>({
    url: '/user/tourist/queryInfo',
    method: 'get'
  })
}

// 获取游客信息
export function getTouristInfo() {
  return request({
    url: '/user/tourist/queryInfo',
    method: 'get'
  })
}

// 更新游客信息
export function updateTouristInfo(data: any) {
  return request({
    url: '/user/tourist/updateInfo',
    method: 'post',
    data
  })
} 